<template>
  <div class="list-table">
    <!--    <div class="area-header">-->
    <!--      <span class="area-header-title">{{ $t('申报数据审核') }}</span>-->
    <!--    </div>-->
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('管理人名称')" prop="gpName">
        <el-input
          v-model="queryParams.gpName"
          :placeholder="$t('管理人名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfPortalDataList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人名称')" align="center" prop="gpName" />
      <el-table-column :label="$t('提交时间')" align="center" prop="submitTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审核状态')" align="center" prop="status" width="130" />
      <el-table-column :label="$t('审核人')" align="center" prop="applyUserName" width="120" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="280">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status === '待审核' || scope.row.status === '同步失败'"
            v-hasPermi="['bfPortal:SB:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="asyncPortalSBData(scope.row)"
          >{{ $t('审核通过') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '待审核' || scope.row.status === '同步失败'"
            v-hasPermi="['bfPortal:SB:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="rejectPortalData(scope.row)"
          >{{ $t('驳回') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '待审核' || scope.row.status === '同步失败'"
            v-hasPermi="['bfPortal:SB:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="viewSBData(scope.row, 'edit')"
          >{{ $t('检查编辑') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '审核通过'"
            v-hasPermi="['fund:gpbase:view']"
            size="small"
            type="text"
            icon="el-icon-view"
          >
            <router-link
              target="_blank"
              :to="{path:'/fund/gpBase/gpBaseHome',query:{ id:scope.row.gpId, gpId: scope.row.gpId }}"
              class="link_a"
            >{{ $t('查看管理人信息') }}</router-link>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listBfPortalSBData,
  getPortalToken,
  asyncPortalSBData,
  rejectPortalSBData
} from '@/api/bf/portal/bfPortalData'

export default {
  data() {
    return {
      // 申报数据遮罩层
      loading: true,
      // 申报数据总条数
      total: 0,
      // 子基金填报-申报数据审核表格数据
      bfPortalDataList: [],
      // 审批状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        dataType: 'SB',
        gpName: undefined,
        year: undefined,
        type: undefined,
        status: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('work_flow_status').then(response => {
      this.statusOptions = response.data
    })
  },
  methods: {
    /** 查询申报数据审核列表 */
    getList() {
      this.loading = true
      listBfPortalSBData(this.queryParams).then(response => {
        this.bfPortalDataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 审批状态字典翻译
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },
    // 表单重置
    reset() {
      this.form = {
        gpId: undefined,
        gpName: undefined,
        status: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    // 查看数据 - 申报数据
    viewSBData(row, view) {
      // 获取临时token
      getPortalToken().then(res => {
        window.open(
          process.env.VUE_APP_BASE_BF_PORTAL_URL + '/login?tempToken=' + res.data + '&gpId=' +
          row.gpId + '&btnView=' + view)
      })
    },
    // 入库操作 - 申报
    asyncPortalSBData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('审核通过之后，数据会同步到对应数据内，是否确认通过?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          this.loading = true
        }).then(function() {
          return asyncPortalSBData(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess(this.$t('审核通过，数据同步成功!'))
        }).catch(function() {
          this.msgError(this.$t('审核未通过，数据同步失败!'))
        })
      }
    },
    // 驳回数据
    rejectPortalData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('是否确认驳回?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          this.loading = true
        }).then(function() {
          return rejectPortalSBData(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess(this.$t('已驳回!'))
        }).catch(function() {
          this.msgError(this.$t('驳回失败!'))
        })
      }
    }
  }
}
</script>
